package spring.concurrency.executor;

import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import spring.concurrency.executor.task.Task2;

public class Main4 {

	public static void main(String[] args) {
		ThreadPoolExecutor executor=(ThreadPoolExecutor)Executors.newCachedThreadPool();
		Task2 task=new Task2();
		System.out.printf("Main: Executing the Task\n");
	    Future<String> result=executor.submit(task);
	    try {
	        TimeUnit.SECONDS.sleep(2);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	    System.out.printf("Main: Canceling the Task\n");
	    result.cancel(true);
	    System.out.printf("Main: Canceled: %s\n",result.isCancelled());
	    System.out.printf("Main: Done: %s\n",result.isDone());
	    executor.shutdown();
	    System.out.printf("Main: The executor has finished\n");
	}

}
